package org.lilred.ui;

import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Keypad;

import org.lilred.ui.theme.Theme;

public abstract class ClickableThemedField extends ThemedField {	
	private boolean disabled;
	
	public ClickableThemedField(Theme unfocus, Theme focus, long style) {
		super(unfocus, focus, style);
	}
	
	public ClickableThemedField(Theme unfocus, Theme focus) {
		super(unfocus, focus);
	}
	
	public boolean isFocusable() {
		return !disabled;
	}
	
	public void enable() {
		disabled = false;
		invalidate();
	}
	
	public void disable() {
		disabled = true;
		invalidate();
	}	

	protected void drawFocus(Graphics graphics, boolean on) {
		return;
	}
	
	protected void onFocus(int direction) {
		super.onFocus(direction);
		invalidate();
	}
	
	protected void onUnfocus() {
		super.onUnfocus();
		invalidate();
	}
	
	protected boolean navigationClick(int status, int time) {
		fieldChangeNotify(0);
		return true;
	}
	
	protected boolean keyChar(char character, int status, int time) {
		if (character == Keypad.KEY_ENTER) {
			fieldChangeNotify(0);
			return true;
		}
		return super.keyChar(character, status, time);
	}
}
